home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kpixmapsplitter.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  3.4 KB  |  124 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.     Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef KPIXMAPSPLITTER_H
  21. #define KPIXMAPSPLITTER_H
  22.  
  23. #include <qpixmap.h>
  24. #include <qrect.h>
  25. #include <qsize.h>
  26. #include <qstring.h>
  27.  
  28. #include <kdelibs_export.h>
  29.  
  30. class KPixmapSplitterPrivate;
  31. /**
  32.  * @short A class to split a pixmap into several items.
  33.  *
  34.  * If you have a pixmap containing several items (icons), you can use this
  35.  * class to get the coordinates of each item.
  36.  *
  37.  * For example, if you have a pixmap with 25 items and you want to get the
  38.  * 4th item as a pixmap (every item being 20x10 pixels):
  39.  * \code
  40.  * KPixmapSplitter splitter;
  41.  * splitter.setPixmap( somePixmap );
  42.  * splitter.setItemSize( QSize( 20, 10 ));
  43.  *
  44.  * QPixmap item( 20, 10 );
  45.  * item.fill( Qt::white );
  46.  * QRect rect = splitter.coordinates( 4 );
  47.  * if ( !rect.isEmpty() )
  48.  *     bitBlt( &item, QPoint(0,0), &somePixmap, rect, CopyROP );
  49.  * \endcode
  50.  *
  51.  * @author Carsten Pfeiffer <pfeiffer@kde.org>
  52.  */
  53. class KDEFX_EXPORT KPixmapSplitter
  54. {
  55. public:
  56.     /**
  57.      * Constructor, does nothing but initialize some default-values.
  58.      */
  59.     KPixmapSplitter();
  60.     ~KPixmapSplitter();
  61.  
  62.     /**
  63.      * Sets the pixmap to be split.
  64.      */
  65.     void setPixmap( const QPixmap& pixmap );
  66.  
  67.     /**
  68.      * @returns the pixmap that has been set via setPixmap().
  69.      */
  70.     const QPixmap& pixmap() const { return m_pixmap; }
  71.  
  72.     /**
  73.      * Sets the size of the items you want to get out of the given pixmap.
  74.      * The QRect of #coordinates(int) will have the width and height of exactly
  75.      * this @p size.
  76.      */
  77.     void setItemSize( const QSize& size );
  78.  
  79.     /**
  80.      * @returns the set size of the items (coordinates) you want to get
  81.      * out of the given pixmap.
  82.      */
  83.     QSize itemSize() const { return m_itemSize; }
  84.  
  85.     /**
  86.      * If there is space between rows in the given pixmap, you have to specify
  87.      * how many pixels there are.
  88.      */
  89.     void setVSpacing( int spacing );
  90.  
  91.     /**
  92.      * If there is space between columns in the given pixmap, you have to
  93.      * specify how many pixels there are.
  94.      */
  95.     void setHSpacing( int spacing );
  96.  
  97.     /**
  98.      * @returns the coordinates of the item at position pos in the given
  99.      * pixmap.
  100.      */
  101.     QRect coordinates( int pos );
  102.  
  103.     /**
  104.      * Overloaded for convenience. Returns the item at the position of the
  105.      * given character (when using a latin1 font-pixmap)
  106.      */
  107.     QRect coordinates( const QChar& ch );
  108.  
  109. private:
  110.     QPixmap m_pixmap;
  111.     QSize m_itemSize;
  112.  
  113.     int m_vSpacing;
  114.     int m_hSpacing;
  115.  
  116.     int m_numCols;
  117.     int m_numRows;
  118.  
  119.     bool m_dirty;
  120.     KPixmapSplitterPrivate* d;
  121. };
  122.  
  123. #endif // KPIXMAPSPLITTER_H
  124.